import request from '@/utils/http';
import type {
  PermissionDefinitionDto,
  PermissionGroupDefinitionDto,
  PermissionTreeDto
} from './type';

enum API {
  PERMINSSION_ALL_URL = '/api/basics/permissions/all',
  PERMINSSION_CURR_URL = 'api/basics/permissions/curr',
  PERMINSSION_GROUP_URL = 'api/basics/permissions/group',
  PERMINSSION_DEFINITION_URL = 'api/basics/permissions/definition'
}

export const reqPermissionCurr = () =>
  request.get<Array<PermissionTreeDto>>(API.PERMINSSION_CURR_URL);

export const reqPermissionAll = () =>
  request.get<Array<PermissionGroupDefinitionDto>>(API.PERMINSSION_ALL_URL);

export const getPermissionGroupDefinitionListAsync = () =>
  request.get<Array<PermissionGroupDefinitionDto>>(API.PERMINSSION_GROUP_URL);

export const getPermissionDefinitionListAsync = (groupName: string) =>
  request.get<Array<PermissionDefinitionDto>>(`${API.PERMINSSION_DEFINITION_URL}/${groupName}`);
